<?php

namespace app\client\model;

use think\Model;
use think\Request;
use app\client\model\Express as ExpressModel;
use app\console\model\MemberMessage as MemberMessageModel;

class MemberOrder extends Model
{
    // 模型事件
    protected static function init()
    {
        // 写入之前
        self::event('before_write', function ($data) {

            // 获取参数
            $information = Request::instance()->param();

            $text = '';

            // 发货
            if ($information['status'] < 3) {
                // 物流地址填写
                if (!empty($information['express_value']) && ($data->status == '2')) {
                    $data->express_name = (new ExpressModel)->where(['code' => $information['express_value']])->value('name');

                    // // 发货消息提醒
                     $model = new MemberMessageModel();
                     $model->save(['member_id' => $data->member_id, 'title' => '您的商品已经发货,订单号：' . $data->order_number, 'content' => '您的商品已经发货,运单号：' . $data->express_number, 'create_time' => time()]);
                }
            }
        });
    }
}